using System;
using System.Collections.Generic;
using System.Linq;
using Survival.Services;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Survival.Components
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class UserInterface : Microsoft.Xna.Framework.DrawableGameComponent, IUserInterface
    {

        IInputService inputService;
        List<UIDialogBox> uiRectangleList;
        SpriteFont interfaceFont;
        SpriteBatch uiBatch;
        
        public UserInterface(Game game)
            : base(game)
        {
            uiRectangleList = new List<UIDialogBox>();         
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();
            uiBatch = new SpriteBatch(GraphicsDevice);
            UIDialogBox.Initialize(GraphicsDevice);
            uiRectangleList.Add(new UIDialogBox(new Rectangle(100, 100, 300,100), Color.YellowGreen, Color.Green));
            inputService = (IInputService)Game.Services.GetService(typeof (IInputService));
        }



        protected override void LoadContent()
        {
            interfaceFont = Game.Content.Load<SpriteFont>("font");


            base.LoadContent();
        }

        public override void Draw(GameTime gameTime)
        {
            uiBatch.Begin();
            foreach (UIDialogBox uiRect in uiRectangleList)
            {
                uiRect.draw(uiBatch,interfaceFont);
            }
            uiBatch.End();
            base.Draw(gameTime);
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {

            base.Update(gameTime);
        }
    }

    public class UIDialogBox
    {
        static Texture2D dummy;
        Color color;
        Color textColor;
        Rectangle rectangle;

        static public void Initialize(GraphicsDevice device)
        {
            dummy = new Texture2D(device, 1, 1);
            dummy.SetData(new Color[] { Color.White });
        }

        public UIDialogBox(Rectangle rect, Color rectColor, Color textColor)
        {
            rectangle = rect;
            color = rectColor;
            this.textColor = textColor;
        }

        public void draw(SpriteBatch batch, SpriteFont font)
        {
            batch.Draw(dummy, rectangle, color);
            batch.DrawString(font, "Long text that won't move to the next line", new Vector2(rectangle.X,rectangle.Y), textColor);
        }
    }
}
